Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom exception printers ignored by ocaml toplevel #7156

Closed
vicuna opened this issue Feb 22, 2016 · 1 comment · Fixed by #8594
Closed

Custom exception printers ignored by ocaml toplevel #7156

vicuna opened this issue Feb 22, 2016 · 1 comment · Fixed by #8594

Comments

@vicuna
Copy link

vicuna commented Feb 22, 2016

Original bug ID: 7156
Reporter: @mjambon
Assigned to: @diml
Status: assigned (set by @mshinwell on 2016-12-08T14:08:42Z)
Resolution: open
Priority: normal
Severity: minor
Version: 4.02.3
Category: toplevel
Tags: junior_job
Monitored by: mfp @diml @hcarty

Bug description

Uncaught exceptions reported by the ocaml toplevel are printed as if no custom printer was registered. Programs compiled with ocamlc or ocamlopt behave as desired and consult the custom printers to print uncaught exceptions.

martin@mj2 ~/tmp $ echo > .ocamlinit
martin@mj2 ~/tmp $ ocaml
        OCaml version 4.02.3

# Printexc.register_printer (fun e -> Some "yo");;
- : unit = ()
# raise Exit;;
Exception: Pervasives.Exit.
# 

When compiled with ocamlc or ocamlopt however, the exception is printed using the custom printers:

martin@mj2 ~/tmp $ cat toto.ml
Printexc.register_printer (fun e -> Some "yo");;
raise Exit;;
martin@mj2 ~/tmp $ ocamlc -c toto.ml
martin@mj2 ~/tmp $ ./toto
Fatal error: exception yo
@vicuna
Copy link
Author

vicuna commented Jan 5, 2017

Comment author: @diml

Indeed. Although I don't think we can just use [Printexc.to_string directly] as it won't print things as good when no printer is registered. Maybe we need a [Printexc.to_string_opt] function.

@vicuna vicuna assigned ghost Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
gasche pushed a commit that referenced this issue Apr 14, 2019
fixes #7156 

Two new functions exposed:

```ocaml
val to_string_default: exn -> string
(** [Printexc.to_string_default e] returns a string representation of the
    exception [e], ignoring all registered exception printers.
    @SInCE 4.09
*)

val use_printers: exn -> string option
(** [Printexc.use_printers e] returns [None] if there are no registered
    printers and [Some s] with else as the resulting string otherwise.
    @SInCE 4.09
*)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant